home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z8.ADF / Ping / rnd.s < prev   
Text File  |  1987-03-28  |  766b  |  42 lines

  1. *\
  2. *  :ts=8
  3. * Yet Another random number generator.  By Leo Schwab.
  4. * Based on an idea posted on the USENET (Thanks, Sam Dicker!)
  5. * For the amiga assembler, Lattice linkage (32-bit arguments) (CS 8703.28)
  6. *
  7. * Calling convention:
  8. *  short rnd (range);
  9. *  short range;
  10. *
  11. * 8606.30
  12. */
  13.  
  14.         xdef    _rnd
  15.  
  16.         section random,code
  17.  
  18. _rnd        lea    rndseed,a0    Get address of seed
  19.         move.l    4(sp),d1    Get range argument
  20.         tst.l    d1
  21.         ble.s    setseed        Go reset seed
  22.  
  23.  
  24.         move.l    (a0),d0        Get seed
  25.         add.l   D0,D0
  26.         bhi.s   over
  27.         eori.l  #$1D872B41,D0
  28. over
  29.         move.l    d0,(a0)        Save new seed
  30.         andi.l    #$ffff,d0    Coerce into word
  31.         divu    d1,d0        Divide by range
  32.         swap    d0         and get remainder (modulus)
  33.         rts
  34.  
  35. setseed        neg.w    d1        Probably don't need this
  36.         move.l    d1,(a0)
  37.         rts
  38.  
  39. rndseed        dc.l    0
  40.  
  41.         end
  42.